<?php
require('main.php');

class Project extends Main{
	
	function Project(){
		parent::Main();
		$this->database();
		$this->lib('message');
		$this->lib('pagination');
	}
	
	/**
	 * 显示案例的列表
	 * service_work,service,work
	 * 
	 * @return unknown_type
	 */
	function show(){
			
		$this->my_view("manage/project/project",$this->workList() );

	}
   
	/**
	 * 
	 * 案例的删除
	 * @return unknown_type
	 */
	function delete(){
		
		$id_sql = join(",",$_POST['id']);
		$result = $this->db->delete("work","id in($id_sql)");
		if($result){
			
			$this->message->set("恭喜你,删除项目成功！");
			$this->my_view("manage/project/project",$this->workList() );
			
		}
		else{
			
			$this->message->set("抱歉,删除项目失败！");
			$this->my_view("manage/project/project",$this->workList() );
			
		}
	}
	
	/**
	 * 
	 * 添加案例
	 * @return unknown_type
	 */
	function init_add(){
		
		$language_list = $this->db->find("select * from languages");
		$service_list  = $this->db->find("select * from service");
		
		$data =  array(
			'language_list' =>$language_list,
			'service_list'  =>$service_list
		);
		
		$this->my_view("manage/project/project_add", $data);
	}
	function add(){
		$data = array(
		'name'			=>$_POST['name'],
		'title'			=>$_POST['title'],
		'summary'		=>$_POST['summary'],
		'content'		=>$_POST['content'],
		'description'	=>$_POST['description'],
		'keywords'		=>$_POST['keywords'],
		'url_pattern'	=>$_POST['url_pattern'],
		'language'		=>$_POST['language'],
		);
        $work_id          = $this->db->insert("work",$data);
        $service_id_array = join(",",$_POST['service_id_string']);            //这里获取的ID 是数组;
        
        foreach($service_id_array as $service_id){
        	 
        }
		
	}
	
	
	
	
	/**
	 * 
	 * 语言列表的查询;
	 */
	function languageList(){
		
		$language_list = $this->db->find("select * from languages");
		
		return array(
		'language_list' =>$language_list
		);
	}
	
	/**
	 * work 数据库的查询
	 * 
	 */
	function workList(){
		$total = $this->db->count("work");
		$config= array(
		'total_row'=>$total
		);
		$this->pagination->init($config);
		$work_list = $this->db->find("select * from work order by created limit "
		            . $this->pagination->start_row.",10");
		return array(
		'work_list'=>$work_list
		);

	}
	
	/**
	 * 
	 * 案例的插入
	 * 
	 */
	function _fetch_form(){
		
	}
	

}
?>